import atlas from "@/atlas";
import Store from "@/store";
// import { setConfig } from "@/setConfig"

let firstEntryPath = {}; // 首次进入路径上携带的参数
// 监听按键key值
const KEYCODE = {
    UP: 19,
    DOWN: 20,
    LEFT: 21,
    RIGHT: 22,
    OK: 23,
    MENU: 82,
    KEY_0: 7,
    KEY_1: 8,
    KEY_2: 9,
    KEY_3: 10,
    KEY_4: 11,
    KEY_5: 12,
    KEY_6: 13,
    KEY_7: 14,
    KEY_8: 15,
    KEY_9: 16,
    LONG_TAP: 1166,
    FLOW_DOWN: 1167,
    PC_OK: 66,
    EXCEPTION: 11099,
    DELETE: 67,
};

// 应用包名，必须要写
const appInfo = {
    packageName: "com.ysten.wk.aroundLife",
    jump: "http://kuaitv.aitv.ysten.com:8082//preview/7111027948791001086/V1.0.1/jump.html?p=",
};
/** 
var deviceInfo = {
  ability: '',   	// 能力串
  username: '',		// 用户名
  deviceId: '',		// 串号
  mac: '',			  // MAC地址
  userToken: '',	// 用户token
  stbid: '',		  // 机顶盒id
  ystenId: '',		// 易视腾id
}
*/

function warn(...context) {
    if (process.env.NODE_ENV === "production") {
        return null;
    }
    return console.warn(...context);
}

/**
 * Better function checking
 */
function isFunction(func) {
    return Object.prototype.toString.call(func) === "[object Function]";
}

function isArray(array) {
    return Object.prototype.toString.call(array) === "[object Array]";
}

function dateFormt(date1, f) {
    let fmt = f;
    const o = {
        "M+": date1.getMonth() + 1, // 月份
        "d+": date1.getDate(), // 日
        "h+": date1.getHours(), // 小时
        "m+": date1.getMinutes(), // 分
        "s+": date1.getSeconds(), // 秒
        "q+": Math.floor((date1.getMonth() + 3) / 3), // 季度
        S: date1.getMilliseconds(), // 毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(
            RegExp.$1,
            `${date1.getFullYear()}`.substr(4 - RegExp.$1.length)
        );
    // eslint-disable-next-line no-restricted-syntax
    for (const k in o)
        if (new RegExp(`(${k})`).test(fmt))
            fmt = fmt.replace(
                RegExp.$1,
                RegExp.$1.length === 1
                    ? o[k]
                    : `00${o[k]}`.substr(`${o[k]}`.length)
            );
    return fmt;
}
//格式化日期formatDate(date,'YYYY-MM-DD hh:mm:ss');
function formatDate(date, format) {
    if (arguments.length < 2 && !date.getTime) {
        format = date;
        date = serverTime;
    }
    typeof format != "string" && (format = "YYYY年MM月DD日 hh时mm分ss秒");
    var week = [
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "日",
        "一",
        "二",
        "三",
        "四",
        "五",
        "六",
    ];
    var tmp;
    return format.replace(
        /YYYY|YY|MM|DD|hh|mm|ss|星期|周|www|week/g,
        function (a) {
            switch (a) {
                case "YYYY":
                    return date.getFullYear();
                case "YY":
                    return (date.getFullYear() + "").slice(2);
                case "MM":
                    tmp = date.getMonth() + 1 + "";
                    return tmp.length == 1 ? "0" + tmp : tmp;
                case "DD":
                    tmp = date.getDate() + "";
                    return tmp.length == 1 ? "0" + tmp : tmp;
                case "hh":
                    tmp = date.getHours() + "";
                    return tmp.length == 1 ? "0" + tmp : tmp;
                case "mm":
                    tmp = date.getMinutes() + "";
                    return tmp.length == 1 ? "0" + tmp : tmp;
                case "ss":
                    tmp = date.getSeconds() + "";
                    return tmp.length == 1 ? "0" + tmp : tmp;
                case "星期":
                    return "星期" + week[date.getDay() + 7];
                case "周":
                    return "周" + week[date.getDay() + 7];
                case "week":
                    return week[date.getDay()];
                case "www":
                    return week[date.getDay()].slice(0, 3);
            }
        }
    );
}
function formatDuring(millisecond, fls) {
    let hours = parseInt(
        (millisecond % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
    );
    hours = hours < 10 ? "0" + hours : hours;
    let minutes = parseInt((millisecond % (1000 * 60 * 60)) / (1000 * 60));
    minutes = minutes < 10 ? "0" + minutes : minutes;
    let seconds = parseInt((millisecond % (1000 * 60)) / 1000);
    seconds = seconds < 10 ? "0" + seconds : seconds;
    if (fls) {
        hours = hours == "00" ? "" : hours + ":";
        minutes = minutes == "00" ? "00:" : minutes + ":";
    }
    return hours + minutes + seconds;
}

function formatTime(millisecond, fls) {
    if (millisecond > 0) {
        let hours = parseInt(
            (millisecond % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
        );
        hours = hours < 10 ? "0" + hours : hours;
        let minutes = parseInt((millisecond % (1000 * 60 * 60)) / (1000 * 60));
        minutes = minutes < 10 ? "0" + minutes : minutes;
        let seconds = parseInt((millisecond % (1000 * 60)) / 1000);
        seconds = seconds < 10 ? "0" + seconds : seconds;
        if (fls) {
            hours = hours == "00" ? "00:" : hours + ":";
            minutes = minutes == "00" ? "00:" : minutes + ":";
            seconds = seconds == "00" ? "00" : seconds;
        }
        return hours + minutes + seconds;
    } else {
        return "00:00:00";
    }
}

// 把字符串处理成时间对象
function handleDate(d) {
    let date = d;
    if (!date && date !== 0) {
        return new Date();
    }
    if (date.toString().indexOf("-") > 0) {
        date = date.replace(/-/g, "/");
        return new Date(date);
    }
    if (date.toString().length === 10) {
        date *= 1000;
    }
    date = parseInt(date, 10);
    return new Date(date);
}

function formatSeconds(value) {
    let h = Math.floor(value / 3600);
    let m = Math.floor((value / 60) % 60);
    let s = Math.floor(value % 60);
    let str = "";
    if (h !== 0) {
        h < 10 ? (str += `0${h}:`) : (str += `${h}:`);
    }
    if (m !== 0) {
        m < 10 ? (str += `0${m}:`) : (str += `${m}:`);
    } else {
        str += `00:`;
    }
    if (s !== 0) {
        s < 10 ? (str += `0${s}`) : (str += `${s}`);
    } else {
        str += `00`;
    }
    // str += `${s}`;
    return str;
}
function handleChanl(str) {
    // 处理频道号的展示
    if (!str) {
        return "";
    }
    if (str.length >= 3) {
        const b = str.substring(str.length - 3);
        return b;
    }
    return handleChanl(`0${str}`);
}

// 频道去重
function filterChannelData(data, key) {
    const newobj = {};
    const newArr = [];
    for (let i = 0; i < data.length; i++) {
        const item = data[i];
        if (!newobj[item[key]]) {
            newobj[item[key]] = newArr.push(item);
        }
    }
    return newArr;
}

function arrFindIndex(list, key, target) {
    for (let i = 0; i < list.length; i++) {
        if (`${list[i][key]}` === `${target}`) {
            return i;
        }
    }
    return -1;
}

// XXX秒转换成00时00分00秒格式
function timeSecondFormat(n, _l) {
    const len = _l || 3;
    const num = parseInt(n, 10);
    if (num >= 0) {
        let h = parseInt(num / 3600, 10);
        let m = parseInt((num % 3600) / 60, 10);
        let s = num % 60;
        h = h > 9 ? h : `0${h}`;
        m = m > 9 ? m : `0${m}`;
        s = s > 9 ? s : `0${s}`;
        switch (len) {
            case 2:
                return { m, s };
            case 3:
                return { h, m, s };
            default:
                return {};
        }
    }
    return {};
}

// 保存首次进入路径上携带的参数
function setFirstEntryPath(params) {
    firstEntryPath = JSON.parse(JSON.stringify(params));
    console.log(
        "setFirstEntryPath.firstEntryPath:" + JSON.stringify(firstEntryPath)
    );
}

// 获取首次进入路径上携带的参数
function getFirstEntryPath() {
    return Store.getData("urlParams") || {};
}
// 跳转
function jumpApp(type, url, json) {
    console.log("log._launchApp:" + url);
    if (!url || url === " ") {
        return;
    }
    if (window.widgetmanager && window.widgetmanager.launchApp) {
        window.widgetmanager.launchApp(type, url, json, true);
    } else {
        if (type === "OpenUrl") {
            window.open(url);
        }
    }
}

function handelAgreeNum(num) {
    var str = "";
    if (num < 100) {
        str = "<100";
    } else if (num >= 100 && num < 10000) {
        str = num;
    } else if (num >= 10000 && num <= 100000) {
        str = Math.floor(num / 10000) + "W+";
    } else {
        str = "10W+";
    }
    return str;
}

// 用于数组对象深层结构查值，不严谨实现
function getObjectPath(paths, data) {
    try {
        let val = data;
        let idx = 0;
        let p;
        while (idx < paths.length) {
            if (val == null || val === undefined) {
                return undefined;
            }
            p = paths[idx];
            val = val[p];
            idx += 1;
        }
        return val;
    } catch (err) {
        // eslint-disable-next-line no-console
        console.log("xxx=== Util.path error");
    }
    return undefined;
}

function capitalize(str) {
    if (typeof str !== "string") {
        return "";
    }
    return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
}

function getEventRedirector(events) {
    const on = {};
    events.forEach((event) => {
        if (Array.isArray(event)) {
            const [exposedEventName, nativeEventName] = event;
            if (
                Object.prototype.hasOwnProperty.call(
                    this.$listeners,
                    exposedEventName
                )
            ) {
                on[event] = this[`on${capitalize(nativeEventName)}`];
            } else {
            }
        } else if (
            Object.prototype.hasOwnProperty.call(this.$listeners, event)
        ) {
            on[event] = this[`on${capitalize(event)}`];
        }
    });
    return on;
}

function ESWaterfallKit(Vue) {
    Vue.registerElement("hi-fast-list-view", {
        component: {
            name: "FastListView",
            processEventData(event, nativeEventName, nativeEventParams) {
                switch (nativeEventName) {
                    case "onLayoutComp":
                        event.focusId = nativeEventParams.focusId;
                        break;
                    case "onItemClick":
                        event.position = nativeEventParams.position;
                        event.index = nativeEventParams.index;
                        event.item = nativeEventParams.item;
                        event.name = nativeEventParams.name;
                        event.parentPosition = nativeEventParams.parentPosition;
                        break;
                    case "onVisiblePosChanged":
                        event.first = nativeEventParams.first;
                        event.last = nativeEventParams.last;
                        break;
                    case "onItemFocused":
                        event.position = nativeEventParams.position;
                        event.index = nativeEventParams.index;
                        event.hasFocus = nativeEventParams.hasFocus;
                        event.isFocused = nativeEventParams.hasFocus;
                        event.item = nativeEventParams.item;
                        event.name = nativeEventParams.name;
                        event.parentPosition = nativeEventParams.parentPosition;
                        break;
                    case "onItemBlured":
                        event.position = nativeEventParams.position;
                        event.index = nativeEventParams.index;
                        event.hasFocus = nativeEventParams.hasFocus;
                        event.isFocused = nativeEventParams.hasFocus;
                        event.item = nativeEventParams.item;
                        event.name = nativeEventParams.name;
                        event.parentPosition = nativeEventParams.parentPosition;
                        break;
                    case "onBindItem":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        break;
                    case "onUnbindItem":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        break;
                    case "onScroll":
                        event.offsetX = nativeEventParams.contentOffset.x;
                        event.offsetY = nativeEventParams.contentOffset.y;
                        break;
                    case "onScrollOffset":
                        event.offsetY = nativeEventParams.y;
                        break;
                    case "onScrollStateChanged":
                        event.offsetX = nativeEventParams.contentOffset.x;
                        event.offsetY = nativeEventParams.contentOffset.y;
                        event.oldState = nativeEventParams.state.oldState;
                        event.newState = nativeEventParams.state.newState;
                        break;
                    case "onPageChanged":
                        event.position = nativeEventParams.position;
                        break;
                    case "onChildFocus":
                        event.child = {
                            index: nativeEventParams.child.index,
                            id: nativeEventParams.child.id,
                            name: nativeEventParams.child.name,
                            position: nativeEventParams.child.position,
                        };
                        event.focused = {
                            id: nativeEventParams.child.id,
                            name: nativeEventParams.child.name,
                        };
                        break;
                    case "onChildSelect":
                        event.child = {
                            index: nativeEventParams.child.index,
                            id: nativeEventParams.child.id,
                            name: nativeEventParams.child.name,
                            position: nativeEventParams.child.position,
                        };
                        break;
                    case "onFocusSearchFailed":
                        event.child = {
                            index: nativeEventParams.child.index,
                            id: nativeEventParams.child.id,
                            name: nativeEventParams.child.name,
                            position: nativeEventParams.child.position,
                        };
                        event.focused = {
                            id: nativeEventParams.child.id,
                            name: nativeEventParams.child.name,
                        };
                        event.direction = nativeEventParams.direction;
                        break;
                    default:
                        break;
                }
                return event;
            },
        },
    });

    // Vue.registerElement('hi-fast-scroll-view', {
    //   component: {
    //     name: 'FastScrollView',
    //     processEventData(event, nativeEventName, nativeEventParams) {
    //       switch (nativeEventName) {
    //         case 'onScroll':
    //           event.offsetX = nativeEventParams.contentOffset.x;
    //           event.offsetY = nativeEventParams.contentOffset.y;
    //           break;
    //         default:
    //           break;
    //       }
    //       return event;
    //     },
    //   },
    // });

    // Vue.component('scroll-view', {
    //   methods: {
    //     onScroll(evt) {
    //       this.$emit('scroll', evt);
    //     }
    //   },
    //   render(h) {
    //     const on = getEventRedirector.call(this, [
    //       ['scroll', 'scroll'],
    //     ]);
    //     return h('hi-fast-scroll-view',
    //       {
    //         on,
    //         ref: 'FastScrollView',
    //       }, this.$slots.default);
    //   },
    // });
    Vue.component("tv-list", {
        methods: {
            onItemClick(evt) {
                this.$emit("item-click", evt);
            },
            onScroll(evt) {
                this.$emit("scroll", evt);
            },
            onScrollStateChanged(evt) {
                debugger
                this.$emit("scroll-state-changed", evt);
            },
            onPageChanged(evt) {
                this.$emit("page-changed", evt);
            },
            onLoadMore(evt) {
                this.$emit("load-more", evt);
            },
            onLayoutComp(evt) {
                this.$emit("layout-comp", evt);
            },
            onVisiblePosChanged(evt) {
                this.$emit("visible-pos-changed", evt);
            },
            onItemFocused(evt) {
                this.$emit("item-focused", evt);
            },
            onItemBlured(evt) {
                this.$emit("item-blured", evt);
            },
            onBindItem(evt) {
                this.$emit("item-bind", evt);
            },
            onUnbindItem(evt) {
                this.$emit("item-unbind", evt);
            },
            hasFocus(callback) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "hasFocus",
                    (res) => {
                        callback(res);
                    }
                );
            },
            updateItemProps(position, name, toUpdateMap, isRefresh) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "updateItemProps",
                    [name, position, toUpdateMap, isRefresh]
                );
            },
            batchUpdateData(data) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "batchUpdateData",
                    [data]
                );
            },
            setListData(data) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setListData",
                    data
                );
            },
            withInsertData(data) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "withInsertData",
                    data
                );
            },
            setTempFocus() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setTempFocus",
                    []
                );
            },
            monitorLayout(id) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "monitorLayout",
                    [id]
                );
            },
            setPageListData(data, focus, name) {
                // console.log('requestChildFocus====pos==',name,data)
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setPageListData",
                    [data, focus]
                );
            },
            notifyItemInserted(data, start, name) {
                // console.log('requestChildFocus====pos==',name,data)
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "notifyItemInserted",
                    [data, start]
                );
            },
            notifyItemRemoved(data, start, name) {
                // console.log('requestChildFocus====pos==',name,data)
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "notifyItemRemoved",
                    [data, start]
                );
            },
            addListData(data) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "addListData",
                    data
                );
            },
            addListDataWithParams(data, position) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "addListDataWithParams",
                    [data, position]
                );
            },
            deleteItemRange(start, count) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "deleteItemRange",
                    [start, count]
                );
            },
            updateItemRange(start, count, data, immediate) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "updateItemRange",
                    [start, count, data, immediate]
                );
            },
            updateItem(position, itemData) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "updateItem",
                    [position, itemData]
                );
            },
            setBlockFocusDirectionsOnFail(data) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setBlockFocusDirectionsOnFail",
                    [data]
                );
            },
            setListDataWithParams(data, autoChangeVisible, position) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setListDataWithParams",
                    [data, autoChangeVisible, position]
                );
            },
            prepareForRecycle() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "prepareForRecycle",
                    []
                );
            },
            setDisplay(b) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setDisplay",
                    [b]
                );
            },
            scrollToTop() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "scrollToTop",
                    []
                );
            },
            changeDisplayState(display, autoDataState) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "changeDisplayState",
                    [display, autoDataState]
                );
            },
            notifySaveInstance() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "notifySaveInstance",
                    []
                );
            },
            notifyRestoreInstance() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "notifyRestoreInstance",
                    []
                );
            },
            pausePostTask() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "pausePostTask",
                    []
                );
            },
            resumePostTask() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "resumePostTask",
                    []
                );
            },
            getScrollOffset(callback) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "getScrollOffset",
                    [],
                    callback
                );
            },
            getScrollPosition(lockFocus, callback) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "getScrollPosition",
                    [lockFocus],
                    callback
                );
            },
            clearFocusMemory() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "clearFocusMemory"
                );
            },
            scrollToPositionWithParams(index) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "scrollToPositionWithParams",
                    [index]
                );
            },
            scrollToPosition(index, fls) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "scrollToPosition",
                    [index, fls]
                );
            },
            setCurrentPage(index) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setCurrentPage",
                    [index]
                );
            },
            scrollToIndex(x, y, anim, offset, duration) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "scrollToPositionWithOffset",
                    [y, offset, anim]
                );
            },
            destroy() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "destroy",
                    []
                );
            },
            requestChildFocus(pos) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "requestChildFocus",
                    [pos]
                );
            },
            onScrollYGreaterReference() {
                this.$emit("scrollYGreaterReference");
            },
            clearPostTask() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "clearAllPostTask",
                    []
                );
            },

            clearFocus() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "clearFocus",
                    []
                );
            },
            onScrollYLesserReference() {
                this.$emit("scrollYLesserReference");
            },
            setSelectChildPosition(pos, b) {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "setSelectChildPosition",
                    [pos, b]
                );
            },
            blockRootFocus() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "blockRootFocus",
                    []
                );
            },
            unBlockRootFocus() {
                Vue.Native.callUIFunction(
                    this.$refs.FastListView,
                    "unBlockRootFocus",
                    []
                );
            },
        },
        render(h) {
            const on = getEventRedirector.call(this, [
                ["layout-comp", "layoutComp"],
                ["load-more", "loadMore"],
                ["visible-pos-changed", "visiblePosChanged"],
                ["item-focused", "itemFocused"],
                ["item-blured", "itemBlured"],
                ["scroll", "scroll"],
                ["item-click", "itemClick"],
                ["item-bind", "bindItem"],
                ["item-unbind", "unbindItem"],
                ["page-changed", "pageChanged"],
                ["scroll-state-changed", "scrollStateChanged"],
                ["scrollYGreaterReference", "scrollYGreaterReference"],
                ["scrollYLesserReference", "scrollYLesserReference"],
            ]);
            return h(
                "hi-fast-list-view",
                {
                    on,
                    ref: "FastListView",
                },
                this.$slots.default
            );
        },
    });

    Vue.registerElement("hi-fast-item-view", {
        component: {
            name: "FastItemView",
            processEventData(event, nativeEventName, nativeEventParams) {
                switch (nativeEventName) {
                    case "onBindItem":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        event.item = nativeEventParams.item;
                        break;
                    case "onItemFocused":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        event.item = nativeEventParams.item;
                        event.parentPosition = nativeEventParams.parentPosition;
                        event.hasFocus = nativeEventParams.hasFocus;
                        break;
                    case "onItemBlured":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        event.item = nativeEventParams.item;
                        event.parentPosition = nativeEventParams.parentPosition;
                        event.hasFocus = nativeEventParams.hasFocus;
                        break;
                    case "onItemRecycled":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        event.item = nativeEventParams.item;
                        break;
                    case "onAttachedToWindow":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        event.item = nativeEventParams.item;
                        break;
                    case "onDetachedFromWindow":
                        event.position = nativeEventParams.position;
                        event.name = nativeEventParams.name;
                        event.item = nativeEventParams.item;
                        break;
                    case "onItemClick":
                        event.position = nativeEventParams.position;
                        event.index = nativeEventParams.index;
                        event.item = nativeEventParams.item;
                        event.name = nativeEventParams.name;
                        event.parentPosition = nativeEventParams.parentPosition;
                        break;
                    default:
                        break;
                }
                return event;
            },
        },
    });

    Vue.component("tv-item", {
        methods: {
            updateItem(posInList, data) {
                Vue.Native.callUIFunction(
                    this.$refs.FastItemView,
                    "updateItem",
                    [posInList, data]
                );
            },
            dispatchItemFunction(position, name, funcName, params) {
                Vue.Native.callUIFunction(
                    this.$refs.FastItemView,
                    "dispatchItemFunction",
                    [position, name, funcName, params]
                );
            },
            updateItemProps(position, name, toUpdateMap) {
                Vue.Native.callUIFunction(
                    this.$refs.FastItemView,
                    "updateItemProps",
                    [name, position, toUpdateMap, true]
                );
            },
            batch(pos) {
                Vue.Native.callUIFunction(this.$refs.FastItemView, "batch", [
                    pos,
                ]);
            },
            onBindItem(evt) {
                this.$emit("item-bind", evt);
            },
            onItemRecycled(evt) {
                this.$emit("item-unbind", evt);
            },
            onAttachedToWindow(evt) {
                this.$emit("item-attached", evt);
            },
            onDetachedFromWindow(evt) {
                this.$emit("item-detached", evt);
            },
            onItemFocused(evt) {
                this.$emit("item-focused", evt);
            },
            onItemClick(evt) {
                this.$emit("item-click", evt);
            },
        },
        render(h) {
            const on = getEventRedirector.call(this, [
                ["item-bind", "bindItem"],
                ["item-unbind", "itemRecycled"],
                ["item-focused", "itemFocused"],
                ["item-attached", "attachedToWindow"],
                ["item-detached", "detachedFromWindow"],
            ]);
            return h(
                "hi-fast-item-view",
                {
                    on,
                    ref: "FastItemView",
                },
                this.$slots.default
            );
        },
    });
    // Vue.component("vertical-text-view", {
    //     render(h) {
    //         return h(
    //             "hi-vertical-text-view",
    //             {
    //                 ref: "YSTVerticalMarqueeTextView",
    //             },
    //             this.$slots.default
    //         );
    //     },
    // });
    // Vue.registerElement("hi-vertical-text-view", {
    //     component: {
    //         name: "YSTVerticalMarqueeTextView",
    //     },
    // });
}

// 数组空过滤
function arrayEmptyFilter(arr) {
    let _arr = [];
    if (arr) {
        for (let i = 0; i < arr.length; i++) {
            if (arr[i]) {
                _arr.push(arr[i]);
            }
        }
        return _arr;
    }
    return _arr;
}

const skyconMap = {
    'CLEAR_DAY': '晴天',
    'CLEAR_NIGHT': '晴夜',
    'PARTLY_CLOUDY_DAY': '多云',
    'PARTLY_CLOUDY_NIGHT': '夜间多云',
    'CLOUDY': '阴天',
    'RAIN': '雨天',
    'SNOW': '雪天',
    'WIND': '大风',
    'HAZE': '雾霾'
}

/**
 * 将天气字段映射为中文字
 * @param {*} key 
 * @returns 
 */
function mapSkyconToText(key) {
    return skyconMap[key]
}

const dayTextList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']

/**
 * 返回当前‘周几’
 * @param {*} dateText 'YYYY-MM-DD'格式日期
 * @returns 
 */
function getDayText(dateText) {
    return dayTextList[new Date(dateText).getDay()];
}

/**
 * 获取风向
 */
function getWindDirText(direction) {
    if (direction > 11.25 && direction < 33.76) {
        return "东北";
    } else if (direction > 33.75 && direction < 56.26) {
        return "东北";
    } else if (direction > 56.25 && direction < 78.76) {
        return "东北";
    } else if (direction > 78.75 && direction < 101.26) {
        return "东";
    } else if (direction > 101.25 && direction < 123.76) {
        return "东南";
    } else if (direction > 123.75 && direction < 146.26) {
        return "东南";
    } else if (direction > 146.25 && direction < 168.76) {
        return "东南";
    } else if (direction > 168.75 && direction < 191.26) {
        return "南";
    } else if (direction > 191.25 && direction < 213.76) {
        return "西南";
    } else if (direction > 213.75 && direction < 236.26) {
        return "西南";
    } else if (direction > 236.25 && direction < 258.76) {
        return "西南";
    } else if (direction > 258.75 && direction < 281.26) {
        return "西";
    } else if (direction > 281.25 && direction < 303.76) {
        return "西北";
    } else if (direction > 303.75 && direction < 326.26) {
        return "西北";
    } else if (direction > 326.25 && direction < 348.76) {
        return "西北";
    } else {
        return "北";
    }
}

function getWindSpeed(speed) {
    if (speed < 1) {
        return "0";
    } else if (1 <= speed && speed < 6) {
        return "1";
    } else if (5 < speed && speed < 12) {
        return "2";
    } else if (11 < speed && speed < 20) {
        return "3";
    } else if (19 < speed && speed < 29) {
        return "4";
    } else if (28 < speed && speed < 39) {
        return "5";
    } else if (38 < speed && speed < 50) {
        return "6";
    } else if (49 < speed && speed < 62) {
        return "7";
    } else if (61 < speed && speed < 75) {
        return "8";
    } else if (74 < speed && speed < 89) {
        return "9";
    } else if (88 < speed && speed < 103) {
        return "10";
    } else if (102 < speed && speed < 118) {
        return "11";
    } else if (117 < speed && speed < 134) {
        return "12";
    } else if (133 < speed && speed < 150) {
        return "13";
    } else if (149 < speed && speed < 167) {
        return "14";
    } else if (167 < speed && speed < 184) {
        return "15";
    } else if (183 < speed && speed < 202) {
        return "16";
    } else if (201 < speed && speed < 221) {
        return "17";
    } else {
        return "18";
    }
}

/**
 * 获取风力风向文字
 */
function getWindText(windItem) {
    const minWindSpeed = getWindSpeed(windItem.min.speed);
    const maxWindSpeed = getWindSpeed(windItem.max.speed); 
    const windDirText = getWindDirText(windItem.avg.direction);
    return `${windDirText}风，${minWindSpeed}~${maxWindSpeed}级`
}

// 设置图标
function setCorner(arr) {
    let obj = {
        position1: {
            img: "",
            visible: "gone",
        },
        position2: {
            img: "",
            visible: "gone",
        },
        position3: {
            img: "",
            visible: "gone",
        },
        position4: {
            img: "",
            visible: "gone",
        },
    };
    if (arr.length) {
        for (let i = 0; i < 4; i++) {
            if (arr[i] && arr[i].position && arr[i].cornerImg) {
                obj["position" + arr[i].position].img =
                    arr[i].cornerImg;
                obj["position" + arr[i].position].visible = "visible";
            }
        }
    }
    return obj;
}


/**
   * @description: 从队列（集合）中获取指定key值对应的value;[[],{},{[],{}},[[],{}]] ; {[],{},{[],{}},[[],{}]}
   * @param {*} key
   * @param {*} arr
   * arr可以是Object 或 Array
   * @return {*}
   */  
function getValue(key, arr) { 
  if (arr instanceof Array) {
    for (var i = 0; i < arr.length; i++) {
      if (typeof arr[i] == 'object') {
        var result = getValue(key, arr[i]);
        if (result) {
          return result;
        }
      }
    }
  }
  if (arr instanceof Object) {
    if (arr["key"] == key) {
      return arr["value"];
    }
    for (key0 in arr) {
      if (typeof arr[key0] == 'object') {
        var result1 = getValue(key, arr[key0]);
        if (result1) {
          return result1;
        }
      }
    }
  }
  return false;
}

export {
    warn,
    isFunction,
    isArray,
    appInfo,
    KEYCODE,
    dateFormt,
    handleDate,
    handleChanl,
    formatDuring,
    filterChannelData,
    arrFindIndex,
    timeSecondFormat,
    setFirstEntryPath,
    getFirstEntryPath,
    formatDate,
    jumpApp,
    getObjectPath,
    formatSeconds,
    formatTime,
    handelAgreeNum,
    ESWaterfallKit,
    arrayEmptyFilter,
    mapSkyconToText,
    getDayText,
    getWindText,
    setCorner,
    getValue
};
